package com.vue.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.vue.pojo.Pay;
import com.vue.service.PayService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/pay")
public class PayController {
    @Autowired
    private PayService payService;

    @RequestMapping("/show")
    public ResponseEntity<Page<Pay>> show(Integer pagenumber, Integer pagesize, String type){
        System.out.println(pagenumber+"---"+pagenumber+"*****"+type);
        Page<Pay> findll = payService.findll(pagenumber, pagesize, type);
        System.out.println(findll.getRecords());
        return new ResponseEntity<>(findll,HttpStatus.OK);
    }

    @RequestMapping("/del")
    public ResponseEntity<String> del(Integer id){
        int i = payService.del(id);
        if(i==1){
            return new ResponseEntity<>("删除成功",HttpStatus.OK);
        }else{
            return new ResponseEntity<>("删除失败",HttpStatus.NOT_FOUND);
        }
    }
    @RequestMapping("/add")
    public ResponseEntity<String> add(String name, String type){
        Pay pay=new Pay();
        pay.setName(name);
        pay.setType(type);
        int i = payService.add(pay);
        if(i==1){
            return new ResponseEntity<>("添加成功",HttpStatus.OK);
        }else{
            return new ResponseEntity<>("添加失败",HttpStatus.OK);
        }
    }
}
